package com.zyzd.general.module.tipdialog;

import android.support.v4.app.Fragment;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;

import com.zyzd.commontools.dialog.TipDialog;
import com.zyzd.general.R;
import com.zyzd.general.entity.local.TipDialogEntity;
import com.zyzd.retrofit.base.BaseRecyclerFragment;

/**
 * Created by lzy on 2018/6/5 0005.
 * description ${信息对话框}
 */
public class TipDialogFragment extends BaseRecyclerFragment<TipDialogContract.IPresenter, TipDialogAdapter, TipDialogEntity> implements TipDialogContract.IView {
    @Override
    public TipDialogAdapter createAdapter() {
        return new TipDialogAdapter(getContext());
    }

    @Override
    protected TipDialogPresenter createPresenter() {
        return new TipDialogPresenter();
    }

    public static Fragment getInstance() {
        return new TipDialogFragment();
    }

    @Override
    public void onItemClick(int position) {
        TipDialogEntity item = mAdapter.getItem(position);
        final TipDialog tipDialog;
        if (item.getLayoutId() != 0) {
            tipDialog = new TipDialog.CustomBuilder(getContext())
                    .setContent(R.layout.dialog_custom)
                    .create();
        } else {
            TipDialog.Builder builder = new TipDialog.Builder(getContext())
                    .setIconType(item.getIconType());
            if (!TextUtils.isEmpty(item.getItemText()))
                builder.setTipWord(item.getTipWord());
            tipDialog = builder.create();
        }
        tipDialog.show();

        mRecyclerView.postDelayed(new Runnable() {
            @Override
            public void run() {
                tipDialog.dismiss();
            }
        }, 2000);

    }

    @Override
    public boolean isEnableLoadMore() {
        return false;
    }

    @Override
    public RecyclerView.ItemDecoration getDividerItemDecoration() {
        return new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL);
    }
}
